package com.life.notes.controller;

import com.life.notes.config.utils.BaseResponse;
import com.life.notes.config.utils.ResponseMsgUtil;
import com.life.notes.dto.RoleMenuQueryPara;
import com.life.notes.model.SysRoleMenuEntity;
import com.life.notes.service.SysRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p> 系统管理 - 角色-菜单关联表  接口 </p>
 *
 * @author: zhengqing
 * @description:
 * @date: 2019-08-20
 *
 */
@RestController
@RequestMapping("/api/system/roleMenu")
@Api(description = "系统管理 - 角色-菜单关联表 接口")
public class SysRoleMenuController {

    @Autowired
    SysRoleMenuService sysRoleMenuService;

    @PostMapping(value = "/listPage", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取系统管理 - 角色-菜单关联表 列表分页", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse listPage(@RequestBody RoleMenuQueryPara filter) {
        return ResponseMsgUtil.success(sysRoleMenuService.listPage(filter));
    }

    @PostMapping(value = "/list", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取系统管理 - 角色-菜单关联表 列表", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse list(@RequestBody RoleMenuQueryPara filter) {
        List<SysRoleMenuEntity> result = sysRoleMenuService.list(filter);
        return ResponseMsgUtil.success(result);
    }

    @PostMapping(value = "/saveOrUpdate", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "保存或更新系统管理 - 角色-菜单关联表 ", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse saveOrUpdate(@RequestBody SysRoleMenuEntity input) {
        Integer id = sysRoleMenuService.saveRoleMenu(input);
        return ResponseMsgUtil.success(id);
    }

    @PostMapping(value = "/delete", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "删除系统管理 - 角色-菜单关联表 ", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse delete(@RequestBody RoleMenuQueryPara input) {
        sysRoleMenuService.removeById(input.getId());
        return ResponseMsgUtil.success("删除系统管理 - 角色-菜单关联表 成功");
    }

    @PostMapping(value = "/detail", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID获取系统管理 - 角色-菜单关联表 信息", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse detail(@RequestBody RoleMenuQueryPara input) {
        SysRoleMenuEntity entity = sysRoleMenuService.getById(input.getId());
        return ResponseMsgUtil.success(entity);
    }

    @PostMapping(value = "/saveRoleMenu", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "保存角色相关联菜单", httpMethod = "POST", response = BaseResponse.class)
    public BaseResponse saveRoleMenu(@RequestBody RoleMenuQueryPara input) {
        sysRoleMenuService.saveRoleMenu( input );
        return ResponseMsgUtil.success("保存角色相关联菜单成功");
    }

}
